package com.firefly.web.controller.admin.mc;

import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.mc.McRoleDto;
import com.firefly.dao.dto.mc.McRoleMenuDto;
import com.firefly.dao.dto.mc.McRoleQueryDto;
import com.firefly.dao.vo.CommonListVo;
import com.firefly.dao.vo.mc.McRolePermissionVo;
import com.firefly.dao.vo.mc.McRoleVo;
import com.firefly.service.command.mc.McRoleCommand;
import com.firefly.service.query.mc.McRoleQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

/**
 * @description: 小程序用户角色
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2023/1/31
 **/
@ConsoleApiRestController("mcrole")
public class McRoleController {
    private final McRoleQuery roleQuery;
    private final McRoleCommand roleCommand;

    @Autowired
    public McRoleController(McRoleQuery roleQuery, McRoleCommand roleCommand) {
        this.roleQuery = roleQuery;
        this.roleCommand = roleCommand;
    }

    @GetMapping("/list")
    public CommonListVo getList(McRoleQueryDto request) {
        return roleQuery.getList(request);
    }

    @GetMapping("/detail")
    public McRoleVo getDetail(@Validated(McRoleQueryDto.showDetail.class) McRoleQueryDto request) {
        return roleQuery.getDetail(request.getDetailId());
    }

    @GetMapping("/priv")
    public List<McRolePermissionVo> getPriv(@Validated(McRoleQueryDto.showDetail.class) McRoleQueryDto request) {
        return roleQuery.getPermission(request);
    }
    @PostMapping("/create")
    public Boolean postCreate(@Validated(McRoleDto.create.class) McRoleDto request) {
        return roleCommand.create(request);
    }

    @PostMapping("/update")
    public Boolean postUpdate(@Validated(McRoleDto.update.class) McRoleDto request) {
        return roleCommand.update(request);
    }

    @PostMapping("/status")
    public Boolean postUpdateStatus(@Validated(McRoleDto.status.class) McRoleDto request) {
        return roleCommand.updateStatus(request);
    }

    @PostMapping("/remove")
    public Boolean postRemove(@Validated(CommonDto.showDetail.class) CommonDto request) throws Exception {
        return roleCommand.remove(request);
    }

    @PostMapping("/removemultiple")
    public Boolean postRemoveMultiple(@Validated(CommonDto.removeMultiple.class) CommonDto request) throws Exception {
        return roleCommand.removeMultiple(request);
    }


    @PostMapping("/priv")
    public Boolean postPriv(@Validated McRoleMenuDto request) {
        return roleCommand.postPermission(request);
    }

}
